<?php

namespace Yolo\Components\Middleware;

use Yolo\Service\RpcRequest;
use Yolo\Service\RpcResponse;

interface MiddlewareInterface
{
    /**
     * Set the priority of this middleware.
     *
     * Those with large values will be executed first
     * @return int
     */
    public function priority(): int;

    /**
     * Filter the middleware base on request.
     * @param RpcRequest $request
     * @return bool Return true if this middleware should skip the request.
     */
    public function filter(RpcRequest $request): bool;

    /**
     * Handle the request.
     * @param RpcRequest $request
     * @param RpcResponse$response
     * @param $next
     * @return mixed
     */
    public function handle(RpcRequest $request, RpcResponse $response, $next): mixed;
}
